package com.example.demo.task;

import com.example.demo.service.ParserNcFileService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class OneHourTask {
    @Resource
    private ParserNcFileService parserNcFileService;

    //3.添加定时任务
    @Scheduled(cron = "0 55 0/1 * * ?")
    private void configureTasks() {
        try {
            parserNcFileService.getFromAllSite(13500, 5720);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

//    @Scheduled(cron = "0/5 * * * * ?")
//    private void fiveMsTask() {
//        /** 测试删除文件 */
//        String url = "D:/data/cldas/20190404/ACHN_MHR_20190404_070000_01.nc";
//        FileUtil.deleteFile(url);
//        System.err.println("执行静态定时任务时间: " + System.currentTimeMillis());
//    }
}
